//
//  LSZNewAudioPlayImageAndTableViewVC.m
//  JKFuYinProject
//
//  Created by 九酷 on 2017/9/27.
//  Copyright © 2017年 LC. All rights reserved.
//

#import "LSZNewAudioPlayImageAndTableViewVC.h"
#import "LSZNewAudioPlayImageAndTableViewVC+LCAVPlay.h"
#import "JKSongsMessStatus.h"
#import "NetworkTool+LCAVPlay.h"
@interface LSZNewAudioPlayImageAndTableViewVC ()

@property (assign,nonatomic) bool isPop;
@property (strong,nonatomic) UIView * viewTopBack;
@property (strong,nonatomic) NSDictionary * dictionAudio;//音频专辑的缓存数据
@end

@implementation LSZNewAudioPlayImageAndTableViewVC
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // 设置导航控制器的代理为self
    self.navigationController.delegate = self;
    [LCFloatingWindow sharedInstance].hidden = NO;////
    if (_isPop) {
        [self reloadTableView];//执行POP的方法，比如你POP回来后需要刷新表格。
    }else{
        //执行PUSH进来时的方法。
    }
    _isPop=YES;//将标志设置为YES。
    [self testData];
}

- (void)dealloc {
    NSLog(@"__func__dealloc = %s", __func__);
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)getDataFrist
{
    self.numberPage = 1;
    [self fromData];
}
//刷新当前的cell数据
-(void)reloadTableView{
    [self.tableViewParticulars reloadData];
    if (_LCPlayer.kstatus == LCMusicPlayerStatusPlaying) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LCPlayStatusStartAnimatingNotification" object:self userInfo:nil];
    }
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [LCFloatingWindow sharedInstance].hidden = YES;
    if(self.viewSharePopover.hidden == NO){
        self.viewSharePopover.hidden = YES;
        self.viewLow.hidden = YES;
        self.butCancel.hidden = YES;
        [LCFloatingWindow sharedInstance].hidden = NO  ;
    }
}
-(void)fromData
{
    //首页音频视频歌手
    if([self.typeComeWhere isEqualToString:@"1"]){
        [self initWithDatWithPages:self.numberPage];
    }
}
-(NSMutableArray *)mutAllOriginalArrayData
{
    if (_mutAllOriginalArrayData == nil) {
        _mutAllOriginalArrayData = [[NSMutableArray alloc]init];
    }
    return _mutAllOriginalArrayData;
}
#pragma mark - 首页音频视频歌手
-(void)ViewTheDataCacheForDetailsOfTheHomeAudio :(NSInteger)page :(NSString *)string
{
    __weak typeof(self) weakSelf = self;
    if ([self.type isEqualToString:@"zhuanji"]||[self.type isEqualToString:@"remen"]) {
        self.type = @"zhuanjilist";
    }
    if ([self.type isEqualToString:@"geshou"]) {
        self.type = @"geshoulist";
    }
    NSString * str = [NSString stringWithFormat:@"%@_%@_%@",shouye_yinpin,self.type,self.parentId];
    [LSZCacheHandling initWithfindPlist:str :^(BOOL isOk, NSDictionary * dic) {
        if (isOk == YES) {
            self.dictionAudio = dic;
            LSZSpecificTypePlayManager * MG = [[LSZSpecificTypePlayManager alloc]initWithSpecificTypePlayManager:dic strLastImageView:weakSelf.strLastImageView];
            [weakSelf.mutArrayData removeAllObjects];
            [weakSelf.mutArrayData addObjectsFromArray:MG.mutDataArray];

            [weakSelf.mutAllOriginalArrayData removeAllObjects];
            [weakSelf.mutAllOriginalArrayData setArray:MG.historyArrayData];

            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [weakSelf.tableViewParticulars reloadData];
            }];
        }else{
             [weakSelf setStringWarning:string];
        }
    }];
}
#pragma mark - 首页音频请求数据
-(void)initWithDatWithPages :(NSInteger)page
{
    if ([self.type isEqualToString:@"zhuanji"]||[self.type isEqualToString:@"remen"]) {
         self.type = @"zhuanjilist";
    }
    if ([self.type isEqualToString:@"geshou"]) {
        self.type = @"geshoulist";
    }
     __weak typeof(self) weakSelf = self;
    [LSZRequestResolutionDic initWithAlbumDetailsPage:[NSString stringWithFormat:@"%ld",(long)page] type:weakSelf.type parentId:weakSelf.parentId strLastImageView:self.strLastImageView :^(BOOL isOK, NSString * Str, LSZSpecificTypePlayManager * sudioManager) {
        if (isOK == YES) {
            if (page == 1) {
                [weakSelf.mutArrayData removeAllObjects];
                [weakSelf.mutArrayData addObjectsFromArray:sudioManager.mutDataArray];
                
                [weakSelf.mutAllOriginalArrayData removeAllObjects];
                [weakSelf.mutAllOriginalArrayData setArray:sudioManager.historyArrayData];
            }
            else{
                [weakSelf.mutArrayData addObjectsFromArray:sudioManager.mutDataArray];
                [weakSelf.mutAllOriginalArrayData addObjectsFromArray:sudioManager.historyArrayData];

            }
            NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
            for (NSInteger i = 0; i < weakSelf.mutAllOriginalArrayData.count; i++) {
                LSZSpecificTypePlayMg *audioMg = [LSZSpecificTypePlayMg yy_modelWithJSON:weakSelf.mutAllOriginalArrayData[i]];
                audioMg.image = weakSelf.strLastImageView;
                NSDictionary *json = [audioMg yy_modelToJSONObject];
                [mutableArray addObject:json];
            }//添加专辑图片

            NSString * distinguishValue =  [LSZSpecialPackaging addPlaylistWithArrayData:weakSelf.mutAllOriginalArrayData];
            
            NSString * strRow = [NSString stringWithFormat:@"11_%@_%@",weakSelf.lastSection,weakSelf.lastPageNumberRow];
            
            if ([distinguishValue isEqualToString:strRow]) {
                LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
                _LCPlayer.songs = playlistTest.allSongs;
            }
            if(sudioManager.mutDataArray.count == 0){
                [weakSelf.tableViewParticulars.mj_footer endRefreshingWithNoMoreData];
            }
            [weakSelf.tableViewParticulars reloadData];
            NSString * str = [NSString stringWithFormat:@"%@_%@_%@",shouye_yinpin,self.type,self.parentId];
            [LSZCacheHandling initWithfindPlist:str :^(BOOL isOk, NSDictionary * dic) {
                if (isOk == YES) {
                    self.dictionAudio = dic;
                }
            }];
        }else{
            [weakSelf  ViewTheDataCacheForDetailsOfTheHomeAudio:1 :Str];
        }
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creareAVPlay];
    _isPop=YES;//将标志设置为YES。
    self.numberRow = -1;//默认点击的是-1行
    self.mutArrayData = [[NSMutableArray alloc]init];

    if ([self.typeStr isEqualToString:@"geshou"]||[self.typeStr isEqualToString:@"geshoulist"]) {
        self.typeStr = @"2";
    }
    else{
        self.typeStr = @"1";
    }
    [self setUiTop];
    [self getDataFrist];
    NSString * stringCollection = [NSString stringWithFormat:@"%@Collection",@"LSZPlayImageAndTableViewVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationSuccessfulSongCollection:) name:stringCollection object:nil];//收藏歌曲成功的通知
    NSString * stringPlayImageAndTableView = [NSString stringWithFormat:@"%@newSongList",@"LSZPlayImageAndTableViewVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(PlayImageAndTableView) name:stringPlayImageAndTableView object:nil];//点击新创文件夹

    NSString * strShare = [NSString stringWithFormat:@"%@",@"LSZPlayImageAndTableViewVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationLSZPlayImageAndTableViewVCShare) name:strShare object:nil];//点击分享歌曲的通知
    NSString * strDownload = [NSString stringWithFormat:@"%@Download",@"LSZPlayImageAndTableViewVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationLSZPlayImageAndTableViewVCDownload) name:strDownload object:nil];//点击下载的通知
    NSString * stringLogin = [NSString stringWithFormat:@"%@Login",@"LSZPlayImageAndTableViewVC"];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationLSZPlayImageAndTableViewVCLogin) name:stringLogin object:nil];//点击收藏  用户没登录
}
#pragma mark - UI
-(void)setUiTop
{
    [self aboveIntroduction];

    [self.tableViewParticulars registerClass:[LSZNewRandombroadcastHeaderCell class] forHeaderFooterViewReuseIdentifier:@"LSZNewRandombroadcastHeaderCell"];
    [self.tableViewParticulars registerClass:[LSZPlayImageTableViewCell class] forCellReuseIdentifier:@"LSZPlayImageTableViewCell"];
    [self.tableViewParticulars registerClass:[LSZNewWithPlusSignAudioTableViewCell class] forCellReuseIdentifier:@"LSZNewWithPlusSignAudioTableViewCell"];
    [self.tableViewParticulars registerClass:[LSZNewAlbumPlaybackInterfaceTableViewCell class] forCellReuseIdentifier:@"LSZNewAlbumPlaybackInterfaceTableViewCell"];
    __weak typeof(self) weakSelf = self;
#pragma mark - 上下拉  加载数据
    // 上拉刷新
    self.tableViewParticulars.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        // 进入刷新状态后会自动调用这个block
        weakSelf.numberPage ++;
        //首页音频视频歌手
        if([weakSelf.typeComeWhere isEqualToString:@"1"]){
            [weakSelf initWithDatWithPages:weakSelf.numberPage];
        }

        [weakSelf.tableViewParticulars.mj_footer endRefreshing];
    }];
    self.viewSharePopover.hidden = YES;
    self.viewLow.hidden = YES;
    self.butCancel.hidden = YES;
    [LCFloatingWindow sharedInstance].hidden = NO;
}
#pragma mark - 分享弹出来的view
-(UIView *)viewSharePopover
{
    if(_viewSharePopover == nil){
        __weak typeof(self) weakSelf = self;
        [LSZSpecialPackaging initAlterView:self.view :^(UIView * viewBack,UIView * viewLow, UIButton * buttonFriends, UIButton * buttonFriendsCircle, UIButton * buttonDownload, UIButton * butCancel) {
            _viewSharePopover = viewBack;
            [weakSelf.view bringSubviewToFront:_viewSharePopover];
            [weakSelf.tableViewParticulars bringSubviewToFront:_viewSharePopover];
            
           
            weakSelf.viewLow = viewLow;
            [weakSelf.view bringSubviewToFront:weakSelf.viewLow];
            [weakSelf.tableViewParticulars bringSubviewToFront:weakSelf.viewLow];
            
            weakSelf.butCancel = butCancel;
            [weakSelf.view bringSubviewToFront:weakSelf.butCancel];
            [weakSelf.tableViewParticulars bringSubviewToFront:weakSelf.butCancel];
 
            [buttonFriends addTarget:weakSelf action:@selector(clickShareWeiXin) forControlEvents:UIControlEventTouchUpInside];
            [buttonFriendsCircle addTarget:weakSelf action:@selector(clickShareWeiXinFriendsCircle) forControlEvents:UIControlEventTouchUpInside];
            [buttonDownload addTarget:weakSelf action:@selector(clickDoenload) forControlEvents:UIControlEventTouchUpInside];
            [butCancel addTarget:weakSelf action:@selector(clickButCancel) forControlEvents:UIControlEventTouchUpInside];
        }];
    }
    return _viewSharePopover;
}
-(void)clickShareWeiXin
{
    NSLog(@"没用");
}
-(void)clickShareWeiXinFriendsCircle
{
    NSLog(@"没用");
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        if (ScreenWidth == 320) {
            //5
            return 35;
        }else if(ScreenWidth == 375){
            // 6 7
            return 40;
        }
        else {
            //plus
            return 48;
        }
    }else{
        return 0.00001;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (ScreenWidth == 320) {
            //5
            return  270-NAVIGATION_BAR_HEIGHT;
        }else if(ScreenWidth == 375){
            // 6 7
            if (iPhoneX) {
                return  280+24-NAVIGATION_BAR_HEIGHT;
            }else{
                return  280-NAVIGATION_BAR_HEIGHT;
            }
        }else {
            //plus
            return  290-NAVIGATION_BAR_HEIGHT;
        }
    }
    else{
        if (ScreenWidth == 320) {
            //5
            return 45;
        }else if(ScreenWidth == 375){
            // 6 7
            return 50;
        }
        else {
            //plus
            return 58;
        }
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else{
        return self.mutArrayData.count;
    }
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if(section == 1){
        LSZNewRandombroadcastHeaderCell * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"LSZNewRandombroadcastHeaderCell"];
        [cell.imageViewPlay tapGesture:^(UIGestureRecognizer *ges) {
            [self clickButRandom];
        }];
        [cell.label tapGesture:^(UIGestureRecognizer *ges) {
            [self clickButRandom];
        }];
        [cell.butPaly addTarget:self action:@selector(clickButRandom) forControlEvents:UIControlEventTouchUpInside];
        //当前播放列表clickNowPlayLists
//        __weak typeof(self) weakSelf = self;
//        [cell.imageViewList tapGesture:^(UIGestureRecognizer *ges) {
//            [weakSelf clickList];
//        }];
//        cell.nowListsBlock = ^{
//            [weakSelf clickList];
//        };
//        cell.viewBig.backgroundColor =RGBColor(241, 239, 248);
//        [cell.butList addTarget:self action:@selector(clickList) forControlEvents:UIControlEventTouchUpInside];
        cell.butList.hidden = YES;
        cell.imageViewList.hidden = YES;
        cell.labelListName.hidden = YES;
        return cell;
    }else{
        UITableViewHeaderFooterView * cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"cell"];
        if (!cell) {
            cell = [[UITableViewHeaderFooterView alloc]initWithReuseIdentifier:@"cell"];
        }
        return cell;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        LSZNewAlbumPlaybackInterfaceTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZNewAlbumPlaybackInterfaceTableViewCell" forIndexPath:indexPath];
        [cell.coverImageView sd_setImageWithURL:[NSURL URLWithString:self.strTopImageView] placeholderImage:[UIImage imageNamed:@"devotion_bannerB"]];
        if ([self.type isEqualToString:@"geshou"]||[self.type isEqualToString:@"geshoulist"]) {
            if (ScreenWidth == 320) {
                //5
                cell.labelName.frame = CGRectMake(CGRectGetMaxX(cell.coverImageView.frame)+15+2, CGRectGetMaxY(cell.albumLabel.frame)-10,  ScreenWidth-CGRectGetMaxX(cell.coverImageView.frame)-20, 16);
                cell.labelIntroduction.frame = CGRectMake(CGRectGetMaxX(cell.coverImageView.frame)+15+2, CGRectGetMaxY(cell.labelName.frame)+40, ScreenWidth-CGRectGetMaxX(cell.coverImageView.frame)-20,45);

            }else if(ScreenWidth == 375){
                // 6 7
                cell.labelName.frame = CGRectMake(CGRectGetMaxX(cell.coverImageView.frame)+15+2, CGRectGetMaxY(cell.albumLabel.frame)-10,  ScreenWidth-CGRectGetMaxX(cell.coverImageView.frame)-20, 18);
                cell.labelIntroduction.frame = CGRectMake(CGRectGetMaxX(cell.coverImageView.frame)+15+2, CGRectGetMaxY(cell.labelName.frame)+40, ScreenWidth-CGRectGetMaxX(cell.coverImageView.frame)-20,45);
            }else {
                //plus
                cell.labelName.frame = CGRectMake(CGRectGetMaxX(cell.coverImageView.frame)+15+2, CGRectGetMaxY(cell.albumLabel.frame)-10,  ScreenWidth-CGRectGetMaxX(cell.coverImageView.frame)-20, 20);
                cell.labelIntroduction.frame = CGRectMake(CGRectGetMaxX(cell.coverImageView.frame)+15+2, CGRectGetMaxY(cell.labelName.frame)+40, ScreenWidth-CGRectGetMaxX(cell.coverImageView.frame)-20,45);
            }
        }else{
            cell.albumLabel.text = [NSString stringWithFormat:@"专辑:%@",self.titleStr];
            if (ScreenWidth == 320) {
                //5
                cell.labelName.frame = CGRectMake(CGRectGetMaxX(cell.coverImageView.frame)+15+2, CGRectGetMaxY(cell.albumLabel.frame)+20,  ScreenWidth-CGRectGetMaxX(cell.coverImageView.frame)-20, 16);
            }else if(ScreenWidth == 375){
                // 6 7
                cell.labelName.frame = CGRectMake(CGRectGetMaxX(cell.coverImageView.frame)+15+2, CGRectGetMaxY(cell.albumLabel.frame)+20,  ScreenWidth-CGRectGetMaxX(cell.coverImageView.frame)-20, 18);
            }else {
                //plus
                cell.labelName.frame = CGRectMake(CGRectGetMaxX(cell.coverImageView.frame)+15+2, CGRectGetMaxY(cell.albumLabel.frame)+20,  ScreenWidth-CGRectGetMaxX(cell.coverImageView.frame)-20, 20);
            }
        }
        cell.labelName.text = [NSString stringWithFormat:@"歌手:%@",self.author];
        if ([self.contentStr isEqualToString:@""]||self.contentStr.length == 0) {
            cell.labelIntroduction.text = @"暂无简介";
        }else{
            cell.labelIntroduction.text = self.contentStr;//简介
        }
//        [cell.labelIntroduction sizeToFit];
        cell.labelPreview.text = [NSString stringWithFormat:@"%@",self.total_song];
        [cell.butCollection addTarget:self action:@selector(clickButCollection) forControlEvents:UIControlEventTouchUpInside];
        [cell.imageViewCollection tapGesture:^(UIGestureRecognizer *ges) {
            [self clickButCollection];
        }];
        [cell.butGiveLike addTarget:self action:@selector(clickButGiveLike) forControlEvents:UIControlEventTouchUpInside];
        [cell.imageViewGiveLike tapGesture:^(UIGestureRecognizer *ges) {
                    [self clickButGiveLike];
        }];
        cell.labelGiveLike.text = [LSZSpecialPackaging theNumberViewsForTheAlbumAhanges:[NSString stringWithFormat:@"%ld",(long)self.likes]];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else if(indexPath.section == 1){
        LSZNewWithPlusSignAudioTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"LSZNewWithPlusSignAudioTableViewCell" forIndexPath:indexPath];
        if (self.mutArrayData.count > indexPath.row) {
            LSZSpecificTypePlayMg * audioMg = nil;
            audioMg = self.mutArrayData[indexPath.row];
            cell.labelSong.text = [NSString stringWithFormat:@"%@",audioMg.title];

            cell.labelAlbums.text = [NSString stringWithFormat:@"%@",audioMg.singerName];
            cell.labelNumber.text = [NSString stringWithFormat:@"%zd",(long)indexPath.row+1];
            //耳机
            [LSZSpecialPackaging adaptiveWidth:cell.labelAlbums str:cell.labelAlbums.text sizeMaxWidth:ScreenWidth sizeMaxHeight:cell.labelAlbums.frame.size.height];
            CGRect rect = cell.imageViewHeadset.frame;
            rect.origin.x = CGRectGetMaxX(cell.labelAlbums.frame)+10;
            cell.imageViewHeadset.frame = rect;
            //次数
            CGRect rectPlays = cell.labelPlaysNumber.frame;
            rectPlays.origin.x = CGRectGetMaxX(cell.imageViewHeadset.frame)+2;
            rectPlays.size.width = ScreenWidth-CGRectGetMaxX(cell.imageViewHeadset.frame)-10;
            cell.labelPlaysNumber.frame = rectPlays;
            cell.labelPlaysNumber.text = [NSString stringWithFormat:@"%@次",audioMg.click];
            cell.butAdd.tag = indexPath.row + 1;
            cell.butMove.tag = indexPath.row + 1;
            [cell.butAdd addTarget:self action:@selector(clickButAdd:) forControlEvents:UIControlEventTouchUpInside];
            [cell.butMove addTarget:self action:@selector(clickButMove:) forControlEvents:UIControlEventTouchUpInside];
            if (_LCPlayer.selectedIndex == indexPath.row &&[cell.labelSong.text isEqualToString:_LCPlayer.playingSong.title]) {
                [cell didSelectRowCellWithIsSystemRed:YES];
            }else{
                [cell didSelectRowCellWithIsSystemRed:NO];
            }
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else{
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        }
        return cell;
    }
}
#pragma mark - 切换歌
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return;
    }
    [self didSelectRowWithIndexPath:indexPath];
}
#pragma mark - 点击顺序播放的按钮
-(void)clickButRandom  {
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    [self didSelectRowWithIndexPath:indexPath];
}
#pragma mark - 点击播放一首
- (void)didSelectRowWithIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row > self.mutArrayData.count||indexPath.row == self.mutArrayData.count){
        return;
    }
    LSZSpecificTypePlayMg * audioMg = self.mutArrayData[indexPath.row];
    if (_LCPlayer.selectedIndex == indexPath.row && [_LCPlayer.playingSong.id isEqualToString:[NSString stringWithFormat:@"%@",audioMg.id_id]]) {
        return;
    }
    //从音频专辑歌手是1有随机播放区头  每日灵修的地方进来的是2   从赞美诗的分类过来的是3
    if([self.typeComeWhere isEqualToString:@"1"]){
        NSString * strRow = [NSString stringWithFormat:@"11_%@_%@",self.lastSection,self.lastPageNumberRow];
        _LCPlayer.valueDistinguish = strRow;
        [LSZSpecialPackaging addPlaylistWithArrayData:self.mutAllOriginalArrayData image:self.strLastImageView];
        [LSZRequestData songClickOnTheDataUpdates:audioMg.id_id :^(BOOL isOk, NSString * str, NSDictionary * dic) {
            if (isOk == YES) {
                //点击数更新OK
                audioMg.originalClick = [NSString stringWithFormat:@"%d",[audioMg.originalClick intValue]+1];
                audioMg.click  = [LSZSpecialPackaging theNumberViewsForTheAlbumAhanges:audioMg.originalClick];
                 [self.tableViewParticulars reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];

                NSArray * arrayDataHC = self.dictionAudio[@"data"];
                NSMutableDictionary * mutDiction = [[NSMutableDictionary alloc]initWithDictionary:self.dictionAudio];
                NSMutableArray * mutArrayDataHC = mutDiction[@"data"];
                int A = 0;
                for (int i = 0; i<arrayDataHC.count; i++) {
                    NSDictionary * dictionHC = arrayDataHC[i];
                    if ([dictionHC[@"id"] isEqualToString:audioMg.id_id]) {
                        NSMutableDictionary * mutDictionHC = mutArrayDataHC[i];
                        [mutDictionHC setValue: [NSString stringWithFormat:@"%d",[audioMg.originalClick intValue]] forKey:@"click"];
                        A = 1;
                    }
                }
                if (A == 1) {
                    NSString * str = [NSString stringWithFormat:@"%@_%@_%@",shouye_yinpin,self.type,self.parentId];
                    [LSZCacheHandling addDicDataCachedDirectly:str NSDictionary:mutDiction];
                }
            }
        }];
    }
    _LCPlayer.playingSong.id = audioMg.id_id;
    LCPlaylist *playlistTest = _PlaylistMgr.allPlaylists.firstObject;
    _LCPlayer.songs = playlistTest.allSongs;
    [_LCPlayer playAtIndex:indexPath.row isSelectPlay:YES];//播放歌曲
}
#pragma mark - 当前列表的点击事件
//-(void)clickList
//{
//    NSLog(@"当前列表的点击事件");
////    [self example7];
//}
#pragma mark - UINavigationControllerDelegate
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
     [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}
#pragma mark - 点击下载的按钮
-(void)clickDoenload
{
    LSZSpecificTypePlayMg * audioMg = nil;
    audioMg = self.mutArrayData[self.shareAndDownloadNumberRow];
    NSDictionary *json = [audioMg yy_modelToJSONObject];
    JKSongsMessStatus *song = [JKSongsMessStatus yy_modelWithJSON:json];
    [kNetworkTool downloadSongWithUrl:song];
}
#pragma mark - 分享或者下载的view   下落
-(void)clickButCancel
{
    _viewSharePopover.hidden = YES;
    self.viewLow.hidden = YES;
    self.butCancel.hidden = YES;
    [LCFloatingWindow sharedInstance].hidden = NO  ;
    self.numberRow = -1;
}
///标签头部底部分割线
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.tableViewParticulars.backgroundColor = [UIColor clearColor];
}
-(void)aboveIntroduction
{
    UIView *bgview = [[UIView alloc] init];
    bgview.backgroundColor = self.tableViewParticulars.backgroundColor;
    [self.view insertSubview:bgview atIndex:0];
    [bgview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self.view);
        make.height.mas_equalTo(self.view.height/2);
    }];
    //NAVIGATION_BAR_HEIGHT
    self.viewTopBack = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,NAVIGATION_BAR_HEIGHT)];
    self.viewTopBack.backgroundColor = RGBColor(46, 49, 54);
    [self.view addSubview:self.viewTopBack];

    UIButton * buttonBack = [[UIButton alloc]initWithFrame:CGRectMake(0, 0 , 70, NAVIGATION_BAR_HEIGHT)];
    [buttonBack addTarget:self action:@selector(clickButBack) forControlEvents:UIControlEventTouchUpInside];
    [self.viewTopBack addSubview:buttonBack];

    UIImageView * imageViewReturn = [[UIImageView alloc]initWithFrame:CGRectMake(20, NAVIGATION_BAR_HEIGHT-34, 11, 20)];
    imageViewReturn.image = [UIImage imageNamed:@"home_nav_button_back"];
    [buttonBack addSubview:imageViewReturn];
    __weak typeof(self) weakSelf = self;
    [imageViewReturn tapGesture:^(UIGestureRecognizer *ges) {
        [weakSelf clickButBack];
    }];
    //标题
    UILabel * labelTitle = [[UILabel alloc]initWithFrame:CGRectMake((ScreenWidth-220)/2, NAVIGATION_BAR_HEIGHT-34, 220, 20)];
    labelTitle.font = FONT_18;
    labelTitle.textColor = [UIColor whiteColor];
    //1是专辑还是2歌手 3歌曲
    if([self.type isEqualToString:@"zhuanji"]||[self.type isEqualToString:@"remen"]||[self.type isEqualToString:@"zhuanjilist"]){
        labelTitle.text = [NSString stringWithFormat:@"专辑"];
    }
    if([self.type isEqualToString:@"geshou"]||[self.type isEqualToString:@"geshoulist"]){
        labelTitle.text = [NSString stringWithFormat:@"歌手"];
    }
    labelTitle.textAlignment = NSTextAlignmentCenter;
    [self.viewTopBack addSubview:labelTitle];
}
#pragma mark - 收藏
-(void)clickButCollection
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVC;
    }else{
        [LSZRequestData CollectionOfAlbumsSingers:self.typeStr resource:self.parentId :^(BOOL isOk, NSString * string, NSDictionary * dic) {
            if (isOk == YES) {
                LSZNewAlbumPlaybackInterfaceTableViewCell * cell = (LSZNewAlbumPlaybackInterfaceTableViewCell *)[self.tableViewParticulars cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0  inSection:0]];
                NSString * msg = [NSString stringWithFormat:@"%@",dic[@"msg"]];
                if ([msg isEqualToString:@"收藏成功"]) {
                    cell.imageViewCollection.image = [UIImage imageNamed:@"收藏完"];
                }else{
                    cell.imageViewCollection.image = [UIImage imageNamed:@"收藏收藏"];
                }
            }
            [self setStringWarning:string];
        }];
    }
//        LSZPopoverViewController * vc = [[LSZPopoverViewController alloc]init];
//        [vc show];
//        [vc selectIndexRowWith:3];//布局
//        [vc getMusicId:self.parentId];//这个id 删除的时候用的
//        //1是专辑还是2歌手 3歌曲
//        if([self.type isEqualToString:@"zhuanji"]||[self.type isEqualToString:@"remen"]||[self.type isEqualToString:@"zhuanjilist"]){
//            [vc distinguishType:@"1"];
//        }
//        else if([self.type isEqualToString:@"geshou"]||[self.type isEqualToString:@"geshoulist"]){
//            [vc distinguishType:@"2"];
//        }
//        else{
//            [vc distinguishType:@"3"];
//        }
//        [vc ChooseTableViewFrame:@"1"];//改变布局
//        [vc fromWhichInterface:@"LSZPlayImageAndTableViewVC"];//vc
//    }
}
#pragma mark - 新建文件夹
-(void)PlayImageAndTableView
{
    //提示框添加文本输入框
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"创建新文件夹"
                                                                   message:@""
                                                            preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * action) {
                                                         for(UITextField *text in alert.textFields){
                                                             //响应事件//得到文本信息
                                                             NSLog(@"确定text = %@", text.text);
                                                             [self addNewFolder:text.text];
                                                         }
                                                     }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * action) {
                                                             //响应事件
                                                             NSLog(@"取消action = %@", alert.textFields);
                                                         }];
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.placeholder = @"输入新建文件夹名字";
    }];
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];
}
#pragma mark - 添加新的文件夹名字
-(void)addNewFolder :(NSString *)string
{
    [LSZRequestData TheAdditionOfFavorites:@"3" name:string :^(BOOL isOK, NSString * string, NSDictionary * dic) {
        if (isOK == YES) {
            NSLog(@"%@",dic);
            NSString * cat =  NullStringjudgment(NSStr(dic[@"data"][@"cat"]));;
            LSZSpecificTypePlayMg * audioMg = nil;
            audioMg = self.mutArrayData[self.shareAndDownloadNumberRow];
            [LSZRequestData getSongCollection:cat :audioMg.id_id :^(BOOL isOk, NSString * string, NSDictionary * dic) {
                [self setStringWarning:string];
            }];
        }else{
            [self setStringWarning:string];
        }
    }];
}
#pragma mark -  点赞
-(void)clickButGiveLike
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVC;
    }else{
        LSZNewAlbumPlaybackInterfaceTableViewCell * cell = (LSZNewAlbumPlaybackInterfaceTableViewCell *)[self.tableViewParticulars cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0  inSection:0]];
        [LSZRequestData audioPointPraise:self.typeStr :self.parentId :^(BOOL isOK, NSString * string, NSDictionary * dic) {
            if (isOK == YES) {
                [self setStringWarning:string];
                if ([string isEqualToString:@"取消成功"]) {
                    cell.imageViewGiveLike.image = [UIImage imageNamed:@"点赞点赞"];
                    if (self.likes <= 0) {
                        self.likes = self.likes;
                    }else{
                        self.likes = self.likes-1;
                    }
                    cell.labelGiveLike.text = [LSZSpecialPackaging theNumberViewsForTheAlbumAhanges:[NSString stringWithFormat:@"%ld",(long)self.likes]];
                }else{
                    cell.imageViewGiveLike.image = [UIImage imageNamed:@"点赞完"];
                    self.likes = self.likes+1;
                    cell.labelGiveLike.text = [LSZSpecialPackaging theNumberViewsForTheAlbumAhanges:[NSString stringWithFormat:@"%ld",(long)self.likes]];
                }
            }else{
                [self setStringWarning:string];
            }
        }];
    }
}
#pragma mark - 检验专辑是否点赞和收藏
-(void)testData
{
    LSZNewAlbumPlaybackInterfaceTableViewCell * cell = (LSZNewAlbumPlaybackInterfaceTableViewCell *)[self.tableViewParticulars cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0  inSection:0]];
    //是否点赞
    [LSZRequestData checkIfTheAudioIsThumbUp:self.typeStr :self.parentId :^(BOOL isOK, NSString * string, NSDictionary * dic) {
        if (isOK == YES) {
            cell.imageViewGiveLike.image = [UIImage imageNamed:@"点赞完"];
        }else{
            cell.imageViewGiveLike.image = [UIImage imageNamed:@"点赞点赞"];
        }
        cell.labelGiveLike.text = [LSZSpecialPackaging theNumberViewsForTheAlbumAhanges:[NSString stringWithFormat:@"%ld",(long)self.likes]];
    }];
    //是否收藏
    [LSZRequestData checkTheCollectionOfSongsOrAlbums:self.typeStr :self.parentId :^(BOOL isOK, NSString * string, NSDictionary * dic) {
        if (isOK == YES) {
            cell.imageViewCollection.image = [UIImage imageNamed:@"收藏完"];
        }else{
            cell.imageViewCollection.image = [UIImage imageNamed:@"收藏收藏"];
        }
    }];
}
#pragma mark - 收藏成功
-(void)InfoNotificationSuccessfulSongCollection:(NSNotification *)notification
{
    LSZNewAlbumPlaybackInterfaceTableViewCell * cell = (LSZNewAlbumPlaybackInterfaceTableViewCell *)[self.tableViewParticulars cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0  inSection:0]];
    NSDictionary * diction = notification.userInfo;
    if ([diction[@"ok"] isEqualToString:@"1"]) {
        [self setStringWarning:@"收藏成功!"];
        cell.imageViewCollection.image = [UIImage imageNamed:@"收藏完"];
    }else{
        [self setStringWarning:diction[@"str"]];
    }
}
-(void)clickButBack
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 新布局添加当前列表和类别
#pragma mark - 添加
-(void)clickButAdd:(UIButton *)but
{
    self.shareAndDownloadNumberRow = but.tag-1;
    if ([_LCPlayer.playingSong.singerName isEqualToString:@"圣经新约"] || [_LCPlayer.playingSong.singerName isEqualToString:@"圣经旧约"]) {
        return;//播放圣经  不能添加歌曲到当前列表
    }
    LCPlaylist *playlist = [LCPlaylist new];
    if (_LCPlayer.songs) {
        playlist.songs = _LCPlayer.songs.mutableCopy;
    }
    JKSongsMessStatus *songsMessStatus;
    LSZSpecificTypePlayMg * mg = nil;
    mg = self.mutArrayData[self.shareAndDownloadNumberRow];
    NSDictionary *json = [mg  yy_modelToJSONObject];
    songsMessStatus = [JKSongsMessStatus yy_modelWithJSON:json];

    [self setStringWarning:[NSString stringWithFormat:@"添加歌曲<<%@>>成功",songsMessStatus.title]];
//    [playlist addSongSelectedIndexLater:songsMessStatus];
    _LCPlayer.songs = playlist.allSongs;
    if (_LCPlayer.songs != nil) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LCMusicPlayerAddSongNotification" object:self userInfo:nil];
    }
}
#pragma mark - 更多 类别
-(void)clickButMove:(UIButton *)but
{
    self.shareAndDownloadNumberRow = but.tag-1;
    LSZSpecificTypePlayMg * audioMg = nil;
    audioMg = self.mutArrayData[but.tag-1];
    LSZPopoverViewController * vc = [[LSZPopoverViewController alloc]init];
    [vc show];
    [vc selectIndexRowWith:2];//布局
    [vc getMusicId:audioMg.id_id];

    [vc distinguishType:@"3"];
    [vc fromWhichInterface:@"LSZPlayImageAndTableViewVC"];
}
#pragma mark  - 分享
- (void)InfoNotificationLSZPlayImageAndTableViewVCShare {
    LSZSpecificTypePlayMg * audioMg = nil;
    audioMg = self.mutArrayData[self.shareAndDownloadNumberRow];
    
//    [self shareMusicWithImageStr:_strTopImageView song:nil musicUrl:audioMg.fileUrl musicWebUrl:audioMg.shareUrl title:audioMg.title contentMessage:audioMg.singerName];
    [self shareAudioWithImageArray:@[_strTopImageView] url:audioMg.fileUrl musicWebURL:audioMg.shareUrl title:audioMg.title contentMessage:audioMg.singerName type:(SSDKContentTypeAudio)];
}
#pragma mark - 下载
-(void)InfoNotificationLSZPlayImageAndTableViewVCDownload
{
    JKSongsMessStatus *songsMessStatus;
    LSZSpecificTypePlayMg * audioMg = nil;
    audioMg = self.mutArrayData[self.shareAndDownloadNumberRow];
    NSDictionary *json = [audioMg yy_modelToJSONObject];
    songsMessStatus = [JKSongsMessStatus yy_modelWithJSON:json];
    [kNetworkTool downloadSongWithUrl:songsMessStatus];//下载歌曲文件
}
#pragma mark - 收到通知  用户未登录
-(void)InfoNotificationLSZPlayImageAndTableViewVCLogin
{
    if([[_UserM usercode] isEqualToString:@""]){
        pushAccLoginVC;
    }
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (self.tableViewParticulars.contentOffset.y <= 0) {
//        self.tableViewParticulars.bounces = NO;
        NSLog(@"禁止下拉");
    }
    else{
        if (self.tableViewParticulars.contentOffset.y >= 0){
//            self.tableViewParticulars.bounces = YES;
            NSLog(@"允许上拉");
        }
    }
}
-(UITableView *)tableViewParticulars
{
    if (_tableViewParticulars == nil) {
        _tableViewParticulars = [[UITableView alloc]initWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, self.view.bounds.size.width, self.view.bounds.size.height - NAVIGATION_BAR_HEIGHT-60-HOME_INDICATOR_HEIGHT) style:UITableViewStylePlain]; 
        _tableViewParticulars.delegate = self;
        _tableViewParticulars.dataSource = self;
        _tableViewParticulars.separatorColor = divider;
        _tableViewParticulars.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);
        //添加以下代码关闭估算行高
        _tableViewParticulars.estimatedRowHeight = 0;
        _tableViewParticulars.estimatedSectionHeaderHeight = 0;
        _tableViewParticulars.estimatedSectionFooterHeight = 0;
        self.view.backgroundColor = [UIColor colorWithRed:0.18 green:0.19 blue:0.21 alpha:1];
        [self.view addSubview:_tableViewParticulars];
    }
    return _tableViewParticulars;
}
@end
